package model;

import java.util.Observable;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * @author Danilov
 *
 */
public class Model extends Observable {

	/**
	 * Is used as a FIFO buffer between communication thread and UI thread
	 */
	private final ConcurrentLinkedQueue<ServerRequest> requests;
	
	public Model() {
		// We use the thread-safe non-blocking queue 
		requests = new ConcurrentLinkedQueue<ServerRequest>();
	}

	/**
	 * Adds <code>ServerRequest</code> to the <code>ConcurrentLinkedQueue</code> which is our <b>FIFO</b>. 
	 * External controller to generate 
	 * @param request is a <code>ServerRequest</code>
	 * @see model.ServerRequest 
	 */
	public void addRequest(ServerRequest request){
			requests.add(request);
	}
	
	/**
	 * Gets available requests for execution
	 * @return <code>ServerRequest</code> if there are any, otherwise  <code>null</code>
	 */
	public ServerRequest getRequest(){
			return (requests.poll());
	}
	
	
	/**
	 * Expanding visibility of this method
	 */
	public void setChanged(){
		// TODO: remove. Expanded for test reasons only
		super.setChanged();
	}

	
}
